package com.fhz.day005.fragment;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.fhz.day005.entity.Food;
import com.fhz.day005.repostroy.FoodRepostroy;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class FoodViewModel extends ViewModel {

    private FoodRepostroy foodRepostroy;


    public FoodViewModel(FoodRepostroy foodRepostroy) {
        this.foodRepostroy = foodRepostroy;
    }

    private MutableLiveData<Food> foodMutableLiveData = new MutableLiveData<>();

    public MutableLiveData<Food> getFoodMutableLiveData() {
        return foodMutableLiveData;
    }

    public void setFoodData(Food data){
        foodMutableLiveData.postValue(data);
    }

    public void getFood(){

        foodRepostroy.getFood(new Observer<Food>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull Food food) {
                foodMutableLiveData.postValue(food);
            }

            @Override
            public void onError(@NonNull Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }
}